package com.sso.manager;

import com.sso.common.ConstantDate;
import com.sso.dao.SysUserMenuMapper;
import com.sso.entity.SysUserMenu;
import com.sso.exception.DataBaseException;
import com.sso.exception.SelectException;
import com.tools.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysUserMenuManager implements BaseManager<SysUserMenu>{
    @Autowired
    private SysUserMenuMapper userMenuDao;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int save(SysUserMenu entity) throws Exception {
        if(StrUtils.isEmpty(entity.getId())){
            entity.setId(ConstantDate.getUUID());
            userMenuDao.insert(entity);
        }else{
            userMenuDao.update(entity);
        }
        return 1;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<SysUserMenu> selectByPage(Map<String, Object> param) {
        return null;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)

    public List<SysUserMenu> selectByProperty(Map<String, Object> param) {
        return userMenuDao.selectByProperty(param);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public long countByProperty(Map<String, Object> param) {
        return 0;
    }

    public int deleteByUserId(String userId) throws Exception {
        Map<String,Object> param = new HashMap<String, Object>();
        param.put("userId",userId);
        return userMenuDao.delete(param);
    }

    public int deleteByMenuId(String menuId) throws Exception {
        Map<String,Object> param = new HashMap<String, Object>();
        param.put("menuId",menuId);
        return userMenuDao.delete(param);
    }

    public List<SysUserMenu> selectByUserId(String userId){
        Map<String,Object> param = new HashMap<String, Object>();
        param.put("userId",userId);
        return this.selectByProperty(param);
    }
}
